<template>
  <div>
    <base-breadcrumb>
      <searchData :search-data="searchArr" @search="search" />
      <a-card :bordered="false">
        <!-- <title-name title="大事记管理" /> -->
        <list-table ref="table" :columns="columns" :request="loadData">
          <template slot="prefix" slot-scope="ref">
            <a-button v-btn-permission="'oa_003_add_01'" type="primary" icon="plus" @click="$nav('add')"> 新增 </a-button>
          </template>
          <template slot="index" slot-scope="text, record, index">
            {{ index + 1 }}
          </template>
          <template slot="auditStatusStr" slot-scope="text, record, index">
            <list-status :status="record.auditStatus" :text="text" />
          </template>
          <template slot="activityDate" slot-scope="text, record, index">
            {{ text | dateFormat('D') }}
          </template>
          <template slot="createTime" slot-scope="text, record, index">
            {{ text | dateFormat('D') }}
          </template>
          <div slot="operation" slot-scope="text, record, index" class="pub-table-list-action">
            <template v-if="isHasPermission">
              <span @click="$nav('detail', { id: record.id })">查看</span>
              <span @click="$nav('add', { id: record.id })">编辑</span>
              <span @click="handleDel(record.id)">删除</span>
            </template>
            <template v-else>
              <span @click="$nav('detail', { id: record.id })">查看</span>
              <template>
                <span v-if="$userInfo().id === record.creatorId" v-btn-permission="'oa_003_edi_02'" @click="$nav('add', { id: record.id })">编辑</span>
                <span v-if="$userInfo().id === record.creatorId" v-btn-permission="'oa_003_del_03'" @click="handleDel(record.id)">删除</span>
              </template>
            </template>
          </div>
        </list-table>
      </a-card>
    </base-breadcrumb>
  </div>
</template>
<script>
import memorabilia from '@/api/office/memorabilia'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject.vue'

export default {
  name: 'a' + Date.now(),
  data() {
    return {
      loading: false,
      queryParam: {},
      searchArr: [
        // {
        //     name: '单位',
        //     valueKey: 'depId',
        //     type: SelectCompanyAndProject
        // },
        {
          name: '单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect
        },
        {
          name: '主题',
          value: 'theme',
          type: 'input'
        },
        {
          name: '活动时间',
          value: 'activityDate',
          type: 'dateRangeFormatx'
        }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          scopedSlots: { customRender: 'index' },
          width: 70
        },
        {
          title: '单位',
          dataIndex: 'depName',
          width: 150
        },
        {
          title: '主题',
          dataIndex: 'theme',
          width: 150
        },

        {
          title: '活动时间',
          dataIndex: 'activityDate',
          scopedSlots: { customRender: 'activityDate' },
          width: 160
        },
        {
          title: '活动地点',
          dataIndex: 'address',
          width: 120
        },
        {
          title: '创建人',
          dataIndex: 'creatorName',
          width: 160
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' },
          width: 160
        },
        // {
        //     title: '状态',
        //     width: this.STATUS_WIDTH,
        //     dataIndex: 'auditStatusStr',
        //     scopedSlots: { customRender: 'auditStatusStr' }
        // },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 200,
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      isHasPermission: this.$currentPost().postCode === 'COADAZG',
      loadData: (p) => memorabilia.findList(Object.assign(p, { query: this.queryParam }))
    }
  },
  created() {
    console.log(this.isHasPermission)
  },
  methods: {
    search(val) {
      this.queryParam = val
      this.$refs.table.getData(null, true)
    },
    handleDel(id) {
      this.$delList3(
        memorabilia.deleteMainById,
        () => {
          this.search({})
        },
        { id }
      )
    },
    handleEdit(record, state) {
      this.$router.push({
        path: 'add',
        query: {
          id: record && record.id,
          state: state
        }
      })
    }
  }
}
</script>
